package com.home766.dao.impl;

import com.home766.dao.ServiceAreaDao;
import com.home766.entity.ServiceArea;
import net.biz.dao.NativeBaseDao;
import net.biz.dao.impl.BaseDaoImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.persistence.Query;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("serviceAreaDaoImpl")
public class ServiceAreaDaoImpl extends BaseDaoImpl<ServiceArea,Long> implements ServiceAreaDao{
	@Autowired
	private NativeBaseDao nativeBaseDao;

	@Override
	public List<ServiceArea> getListByShopsCode(String shopsCode) {
		// TODO Auto-generated method stub
		String sql =" select sarea.id as id,sarea.area_id as area_Id,area.`name` as area_Name from 766_service_area sarea"
				+ " inner join xx_area area on area.id = sarea.area_id"
				+ " where sarea.shops_code=:shopsCode";
		Map<String,Object> tempMap = new HashMap<String, Object>();
		tempMap.put("shopsCode", shopsCode);
		return nativeBaseDao.findList(sql, tempMap, ServiceArea.class);
	}

	@Override
	public int deleteByCode(String shopsCode) {
		// TODO Auto-generated method stub
		String sql = " delete from 766_service_area where 766_service_area.shops_code=:shopsCode";
		Query query = entityManager.createNativeQuery(sql);
		query.setParameter("shopsCode",shopsCode);
		int num = query.executeUpdate();
		return num;
	}
}
